<html>
<head><meta charset="utf-8"><title>Parse And Expansion · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html">Parse And Expansion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246817527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246817527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246817527">(Jul 22 2021 at 07:44)</a>:</h4>
<p>I'm a little curious why are "parse" and "expansion" are two different phases? I feel the "parse" phase is just "crate root parse" or "primary parse" or something like that,  and maybe it's reasonable to be invoked by the expansion process? I'm raising this question because i saw <a href="https://github.com/rust-lang/rust/issues/64197">#64197</a> . cc <span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span></p>



<a name="246831684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246831684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246831684">(Jul 22 2021 at 10:45)</a>:</h4>
<p>Does some documentation says that parsing and expansion are "phases"?</p>



<a name="246831808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246831808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246831808">(Jul 22 2021 at 10:46)</a>:</h4>
<p>Right now parsing, expansion and (early) name resolution are not phases but rather compiler areas, roughly corresponding to <code>rustc_parse</code>, <code>rustc_expand</code> and <code>rustc_resolve</code> crates.</p>



<a name="246831842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246831842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246831842">(Jul 22 2021 at 10:47)</a>:</h4>
<p>They all call each other recursively in a single top-level algorithm.</p>



<a name="246833025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246833025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246833025">(Jul 22 2021 at 11:05)</a>:</h4>
<p>I remembered i read it somewhere, but i couldn't find it now.</p>
<p>This callback struct also leads to me thinking this way.<br>
<a href="https://github.com/rust-lang/rust/blob/1.53.0/compiler/rustc_driver/src/lib.rs#L85">https://github.com/rust-lang/rust/blob/1.53.0/compiler/rustc_driver/src/lib.rs#L85</a></p>
<p>and also these queries here:</p>
<p><a href="https://github.com/rust-lang/rust/blob/1.53.0/compiler/rustc_driver/src/lib.rs#L368">https://github.com/rust-lang/rust/blob/1.53.0/compiler/rustc_driver/src/lib.rs#L368</a></p>



<a name="246833278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246833278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246833278">(Jul 22 2021 at 11:09)</a>:</h4>
<p>Somehow i feel maybe it's a unified, hir building process(also pulling in dependencies represented by DefIds and other things). Maybe the <code>parse</code> and <code>expansion</code> queries should not be separated... ?</p>



<a name="246834164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246834164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246834164">(Jul 22 2021 at 11:23)</a>:</h4>
<p>Maybe.<br>
The <code>after_parsing</code> callback is extremely useless now, the <code>extern_mod_loaded</code> callback executed on every module loading serves its role now.<br>
The <code>parse</code> query only produces the crate root now, a "seed" for all the further combined resolution-expansion-parsing.</p>



<a name="246838452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/246838452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#246838452">(Jul 22 2021 at 12:16)</a>:</h4>
<p><span class="user-mention" data-user-id="123856">@Vadim Petrochenkov</span> can you open an E-easy/mentor issue for getting rid of after_parsing? I'm sure someone will grab it pretty quick :)</p>



<a name="247313913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Parse%20And%20Expansion/near/247313913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Parse.20And.20Expansion.html#247313913">(Jul 27 2021 at 09:59)</a>:</h4>
<p>I wonder if we could get rid of the root parsing and treat it as a module. so the crate AST starts out sort of empty, with just a placeholder or something, and then the iterative/recursive expand&lt;-&gt;resolve algorithm gets engaged?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>